export default {
	bind(el, binding) {
		el.addEventListener('touchstart', (e) => {
			el.$startX = el.clientX
			el.$startY = el.clientY
			el.$startTime = + new Date()

			el.$timer = setTimeout(() => {
				binding.value(el.dataset.id)
			}, 600)
		})

		el.addEventListener('touchmove', (e) => {
			const startX = e.target.clientX
			const startY = e.target.clientY

			if (Math.abs(startX - el.startX) > 20 || Math.abs(startY - el.startY) > 20) {
				clearTimeout(el.$timer)
			}
		})

		el.addEventListener('touchend', (e) => {
			if (+ new Date() - el.$startTime < 600) {
				clearTimeout(el.$timer)

				// e.preventDefault()
			}
		})
	}
}